package com.pcbly.web.components.utils.jfreechart;

import java.awt.Color;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.CategoryLabelPositions;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.BarRenderer3D;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;

public class BarChart3D extends AbstractChartFont {
	/**
	 * 获取数据集
	 * 
	 * @return
	 */
	public CategoryDataset getDataSet() {
		String str = "学生人数统计";
		// 创建横坐标的现实内容
		String s1 = "湖南";
		String s2 = "上海";
		String s3 = "北京";
		String s4 = "浙江";
		String s5 = "辽宁";

		DefaultCategoryDataset categoryDataset = new DefaultCategoryDataset();
		categoryDataset.addValue(200, str, s1);
		categoryDataset.addValue(300, str, s2);
		categoryDataset.addValue(600, str, s3);
		categoryDataset.addValue(560, str, s4);
		categoryDataset.addValue(670, str, s5);

		return categoryDataset;
	}

	/**
	 * 创建JFreeChart对象
	 * 
	 * @param categoryDataset
	 * @return
	 */
	public JFreeChart createJFreeChart(CategoryDataset categoryDataset) {
		JFreeChart chart = ChartFactory.createBarChart3D("学生生源统计柱状分析图", "省份",
				"学生数量", categoryDataset, PlotOrientation.VERTICAL, true, true,
				false);
		this.configFont(chart);
		chart.setBackgroundPaint(Color.WHITE);
		CategoryPlot categoryPlot = chart.getCategoryPlot();

		categoryPlot.setOutlineVisible(false);
		categoryPlot.setDomainGridlinePaint(Color.WHITE);
		categoryPlot.setDomainGridlinesVisible(true);
		categoryPlot.setBackgroundPaint(Color.WHITE);

		categoryPlot.setRangeGridlinePaint(Color.BLUE);

		CategoryAxis categoryaxis = categoryPlot.getDomainAxis();
		categoryaxis.setCategoryLabelPositions(CategoryLabelPositions
				.createUpRotationLabelPositions(0.39D));
		categoryaxis.setCategoryMargin(0.0D);
		BarRenderer3D barrenderer3d = (BarRenderer3D) categoryPlot
				.getRenderer();
		barrenderer3d.setDrawBarOutline(false);

		return chart;
	}

	public JFreeChart index() {
		CategoryDataset dataset = getDataSet();
		return createJFreeChart(dataset);
	}
}
